package com.twu.module1;

import org.junit.Test;

import java.util.ArrayList;

import static com.google.common.collect.Lists.newArrayList;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;


public class UtilitiesTest {

    @Test
    public void findAllFactorsShouldFindCorrectly() {
        ArrayList<Integer> expected = newArrayList();
        expected.add(2);
        expected.add(4);
        expected.add(5);
        expected.add(10);
        expected.add(20);
        expected.add(25);
        expected.add(50);
        expected.add(100);

        assertThat(Utilities.getAllFactorsExceptOne(100), is(expected));
    }

    @Test
    public void isPrimeShouldReturnCorrectResult() {
        assertTrue(Utilities.isPrime(7));
    }

    @Test
    public void primeFactorsOf1ShouldReturnEmptyList() {
        ArrayList<Integer> expected = newArrayList();
        assertThat(Utilities.primeFactors(1), is(expected));
    }

    @Test
    public void primeFactorsShouldReturnPrimes() {
        ArrayList<Integer> expected = newArrayList();
        expected.add(3);
        expected.add(7);
        expected.add(11);
        expected.add(13);
        expected.add(37);
        assertThat(Utilities.primeFactors(111111), is(expected));
    }

    @Test
    public void lineOfCharactersShouldReturnCorrectLine() {
        String expectedLine = "*****";
        assertThat(Utilities.lineOfCharacters(5, "*"), is(expectedLine));
    }

    @Test
    public void getAllFactorsShouldReturnCorrectFactors() {
        ArrayList<Integer> expected = newArrayList();

        expected.add(2);
        expected.add(4);
        expected.add(7);
        expected.add(8);
        expected.add(14);
        expected.add(28);
        expected.add(56);

        assertThat(Utilities.getAllFactorsExceptOne(56), is(expected));
    }


}
